package com.yunyao.common.constant.enums;

import lombok.Getter;

/**
 * 项目、供货订单状态
 * @author chenyejian
 * @date 2024-07-21
 */
@Getter
public enum OrderStatus {
    WAIT_SUBMIT_STRING("a.audit_status=0", "待提交"),
    APPROVAL_IN_PROGRESS_STRING("a.audit_status=1", "审批中"),
    APPROVAL_REJECTED_STRING("a.audit_status=3", "审批驳回"),
    APPROVAL_REVOKE_STRING("a.audit_status=4", "撤回"),
    PROJECT_ACCEPTANCE_APPROVAL_REVOKE_STRING("a.audit_status=4&a.supply_status=8", "项目验收审批撤回"),
    PROJECT_ACCEPTANCE_APPROVAL_REJECTED_STRING("a.audit_status=3&a.supply_status=8", "项目验收审批驳回"),
    SUPPLIER_AWAITING_CONFIRMATION_STRING("a.supply_status=1", "待供应商确认"),
    SUPPLIER_CONFIRMATION_REJECTED_STRING("a.supply_status=2", "待供应商确认驳回"),
    SUPPLY_ING_STRING("a.supply_status=3", "待供货"),
    SUPPLY_IN_PROGRESS_STRING("a.supply_status=4", "供货中"),
    SUPPLY_COMPLETED_STRING("a.supply_status=5", "供货完成"),
    SUPPLY_DELAYED_STRING("a.supply_status=6", "供货延迟"),
    /**
     * 订单状态 两位数，第一位表示auditStatus，第二位表示supplyStatus
     */
    WAIT_SUBMIT("00", "待提交"),
    APPROVAL_IN_PROGRESS("10", "审批中"),
    APPROVAL_REJECTED("30", "审批驳回"),
    APPROVAL_REVOKE("40", "撤回"),
    PROJECT_ACCEPTANCE_APPROVAL_REVOKE("48", "项目验收审批撤回"),
    PROJECT_ACCEPTANCE_APPROVAL_REJECTED("38", "项目验收审批驳回"),
    SUPPLIER_AWAITING_CONFIRMATION("01", "待供应商确认"),
    SUPPLIER_CONFIRMATION_REJECTED("02", "待供应商确认驳回"),
    SUPPLY_ING("03", "待供货"),
    SUPPLY_IN_PROGRESS("04", "供货中"),
    SUPPLY_COMPLETED("05", "供货完成"),
    SUPPLY_DELAYED("06", "供货延迟");

    private final String type;
    private final String description;

    OrderStatus(String type, String description) {
        this.type = type;
        this.description = description;
    }

    /**
     * 可以根据 type 获取枚举实例 supplyStatus=1 等字符
     */
    public static String getDescriptionByType(String type) {
        for (OrderStatus status : OrderStatus.values()) {
            if (type.equalsIgnoreCase(status.getType())) {
                return status.getDescription();
            }
        }
        return "";
    }

    /**
     * 可以根据 description 获取枚举实例
     */
    public static String getTypeStringByDesc(String description) {
        for (OrderStatus status : OrderStatus.values()) {
            if (description.equalsIgnoreCase(status.getDescription())) {
                if (status.getType().length() == 2){
                    continue;
                }
                return status.getType();
            }
        }
        return "";
    }


    /**
     * 可以根据 description 获取枚举实例
     */
    public static String getTypeByDesc(String description) {
        for (OrderStatus status : OrderStatus.values()) {
            if (description.equalsIgnoreCase(status.getDescription())) {
                return status.getType();
            }
        }
        return description;
    }
}
